<?php
class V1_manage extends CI_Controller{
	 function V1_manage(){
	  	parent::__construct();
	 }
	 function index(){
	 	$htdocs=$this->load->get_var('htdocs');
	 	if($htdocs===false){
			$data['select']=$this->catalog->get(array('where'=>array('catalog'=>'htdocs','locked'=>0),'order'=>array('parent'=>'ASC')));
	 		$this->load->view('manage.htdocs.php',$data);
	 	}else{
	 		$this->load->view('manage.index.php');
	 	}
	 }
	 function login(){
	 	if(LOGIN===true){
	 		header('Location: /manage.html');
	 	}else{
	 		if($this->input->server('REQUEST_METHOD')=='POST'){
		 		$data['username']=$this->input->post('username',true);
		 		$data['password']=$this->input->post('password',true);
		 		if(empty($data['username'])){
		 			$data['message']['username']='用户名不可为空';
		 		}else if(empty($data['password'])){
		 			$data['message']['password']='密码不可为空';
		 		}else{
		 			$this->load->model('admin');
		 			$admin=reset($this->admin->get(array('where'=>array('username'=>$data['username'],'locked !='=>10))));
		 			if(empty($admin)){
		 				$data['message']['username']='没有该用户名';
		 			}else if(md5($data['username'].$data['password']) !=$admin['password']) {
		 				$data['message']['password']='密码错误';
		 			}else{
		 				$_SESSION['id']=$admin['id'];
		 				$_SESSION['username']=$admin['username'];
		 				$this->admin->update(array('where'=>array('username'=>$data['username']),'set'=>array('last'=>time(),'faileds'=>intval($admin['faileds'])+1)));
		 				header('Location: /manage.html');
		 				exit();
		 			}
		 		}
	 		}
	 		$this->load->view('manage.login.php',$data);
	 	}
	 }
	 function system(){
		$this->load->view('manage.system.php');
	 }
	 function password(){
	 	if($this->input->server('REQUEST_METHOD')=='POST'){

	 	}
	 	$this->load->view('manage.password.php');
	 }
	 function quit(){
		session_destroy();
		header('Location: /manage/login.html');
	 }
}
?>